
import { defineStore } from "pinia";
import homeApi from '@/api/index'
import type { focus, cate, policy, kingKong, indexActivity, styleItem } from '@/api/index'

interface useHomeStoreData {
  categoryList: any
  focusList: focus[]
  categoryHotSellModule: {
    categoryList: cate[],
    title: string,
    titleTargetUrl: string
  }
  policyDescList: policy[]
  kingKongList: kingKong[]
  indexActivityModule: indexActivity[]
  sceneLightShoppingGuideModule: styleItem[]


}
export const useHomeStore = defineStore('home', {
  state(): useHomeStoreData {
    return {
      focusList: [],
      categoryHotSellModule: {
        categoryList: [],
        title: "",
        titleTargetUrl: ""
      },
      categoryList: {
        category: [],
        itemIdList: [],
        itemList: []
      },
      policyDescList: [],
      kingKongList: [],
      indexActivityModule: [],
      sceneLightShoppingGuideModule: []

    }
  },
  actions: {
    async getHome() {
      try {
        const res = await homeApi.getIndex()
        // console.log(res);
        this.categoryList = res.data.categoryHotSellModule.categoryList
        this.focusList = res.data.focusList
        this.categoryHotSellModule = res.data.categoryHotSellModule
        this.policyDescList = res.data.policyDescList
        this.kingKongList = res.data.kingKongModule
        this.indexActivityModule = res.data.indexActivityModule
        this.sceneLightShoppingGuideModule = res.data.sceneLightShoppingGuideModule

      } catch (error) {
        console.log(error);

      }
    }
  },
  getters: {
    twocategoryList(state) {
      return state.categoryHotSellModule.categoryList.slice(0, 2)
    },
    leftOvercategoryList(state) {
      let num = state.categoryHotSellModule.categoryList.length
      return state.categoryHotSellModule.categoryList.slice(2, num)
    },
    activeTop(state) {
      return state.indexActivityModule
    }


  }
})